package leetcode.Arrays;

public class 旋转数组 {
    public static void main(String[] args) {
        int[] nums = new int[]{1,2,3,4,5,6};
        rotate2(nums, 3);
        for (int i :
                nums) {
            System.out.print(i + ",");
        }
    }

    public static void rotate(int[] nums, int k){
        int index = 0;
        int tmp = nums[0];
        for(int i = 0; i < nums.length; i++){
            int tmp_index = 0;
            if( (index + k) > nums.length) {
                tmp_index = index + k - nums.length;
            } else {
                tmp_index = index + k;
            }
            tmp = nums[tmp_index];
        }
    }

    public static void rotate2(int[] nums, int k){
        int index = 0;
        int tmp = nums[0];
        int tmp2 = nums[0];
        for(int j = 0; j < k; j++) {
            for (int i = 0; i < nums.length; i++) {
                if (i + 1 == nums.length) {
                    nums[0] = tmp;
                } else {
                    tmp2 = nums[i + 1];
                    nums[i + 1] = tmp;
                    tmp = tmp2;
                }
            }
        }
        System.out.println();
    }
}
